<?php

namespace common\model;

use think\model\RelationModel;
use teamones\dbeventObserver\interfaces\SplSubject;
use teamones\dbeventObserver\SplSubjectEnforcer;

class TaskUpstreamTransModel extends RelationModel implements SplSubject
{
    use SplSubjectEnforcer;

    const STATUS_WAIT_UPLOAD = 'wait_upload'; // 待上传
    const STATUS_WAIT_DOWNLOAD = 'wait_download'; // 待下载
    const STATUS_WAIT_UPDATE = 'wait_update'; // 待更新
    const STATUS_IS_UPLOADED = 'is_uploaded'; // 已上传
    const STATUS_IS_DOWNLOADED = 'is_downloaded'; // 已下载
    const STATUS_IS_UPDATED = 'is_updated'; // 已更新

    const STATUS_GROUP_WAIT = [
        self::STATUS_WAIT_UPLOAD,
        self::STATUS_WAIT_DOWNLOAD,
        self::STATUS_WAIT_UPDATE,
    ];
    const STATUS_GROUP_DONE = [
        self::STATUS_IS_UPLOADED,
        self::STATUS_IS_DOWNLOADED,
        self::STATUS_IS_UPDATED,
    ];


    //自动验证
    protected $_validate = [
        ['from_tenant_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['from_project_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['from_task_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['to_tenant_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['to_project_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['to_task_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['status', [
            'wait_upload', 'wait_download', 'wait_update',
            'is_uploaded', 'is_downloaded', 'is_updated'
        ], '', self::EXISTS_VALIDATE, 'in'],
        ['is_unzip', ['default', 'yes', 'no'], '', self::EXISTS_VALIDATE, 'in'],
        ['is_assemble', ['default', 'yes', 'no'], '', self::EXISTS_VALIDATE, 'in'],
    ];

    //自动完成
    protected $_auto = [
//        ['tenant_id', 'auto_fill_tenant_id', self::MODEL_INSERT, 'function'],
        ['created_by', 'fill_created_by', self::MODEL_INSERT, 'function'],
        ['created', 'time', self::MODEL_INSERT, 'function'],
        ['updated', 'time', self::MODEL_UPDATE, 'function'],
    ];
}
